/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ihm;

import com.ihm.actions.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import com.dao.*;

public class HistoriquePanelFenetre extends JPanel 
{

    private JPanel paneltop;
    private JPanel paneltrier;
    private JPanel panelmiddle;
    private JPanel panelbas;
    private JPanel panelbasmiddle;
    private JPanel panelbasdroite;
    private JPanel panelbasgauche;
    private JPanel panelbasmiddlehaut;
    private JPanel panelbasmiddlebas;
    private JLabel labelcarte;
    private JLabel ListeLieu;
    private JLabel lieu;
    private JLabel trier;
    private JComboBox triercombo;
    private JLabel labelrecherche;
    private JLabel nomdulieu;
    private JLabel dateajout;
    private JTextField textnom;
    private JTextField dateajoute;
    private JButton buttonrecherche;
    private ArrayList<JPanel> listpanel;
    private HistoriquePreparedRequete carteps;
    private JScrollPane js;
    
    public HistoriquePanelFenetre()
    {
        this.setBackground(Color.white);
	this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
	createpanel();
	createcomponent();
	addcomponent();
	this.add(paneltop);
	this.add(panelmiddle);
	this.add(Box.createVerticalGlue());
	this.add(panelbas);
	
        carteps = new HistoriquePreparedRequete();
        try 
        {
            carteps.afficher();
        } 
        catch (SQLException e) 
        {
            e.printStackTrace();
        }
        
        listpanel = new ArrayList<>();
	createlist();
      }
      
      public void createpanel()
      {
            paneltop = new JPanel();
	    paneltop.setMaximumSize(new Dimension(700,200));
	    paneltop.setSize(new Dimension(700,200));
	    paneltop.setLayout(new BoxLayout(paneltop,BoxLayout.X_AXIS));
            paneltop.setBackground(Color.white);

	    panelmiddle = new JPanel();
            panelmiddle.setMaximumSize(new Dimension(700,500));
            panelmiddle.setSize(new Dimension(700,500));
	    panelmiddle.setLayout(new BoxLayout(panelmiddle,BoxLayout.Y_AXIS));
            panelmiddle.setBackground(Color.white);
            
	    panelbas = new JPanel();
	    panelbas.setMaximumSize(new Dimension(700,200));
	    panelbas.setSize(new Dimension(700,200));
	    panelbas.setLayout(new BoxLayout(panelbas,BoxLayout.X_AXIS));
            panelbas.setBackground(Color.white);
            
	    panelbasgauche = new JPanel();
	    panelbasgauche.setMaximumSize(new Dimension(300,200));
	    panelbasgauche.setSize(new Dimension(300,200));
            panelbasgauche.setBackground(Color.white);
            
	    panelbasmiddle = new JPanel();
	    panelbasmiddle.setMaximumSize(new Dimension(500,200));
	    panelbasmiddle.setSize(new Dimension(500,200));
	    panelbasmiddle.setLayout(new BoxLayout(panelbasmiddle,BoxLayout.Y_AXIS));
            panelbasmiddle.setBackground(Color.white);
            
	    panelbasdroite = new JPanel();
	    panelbasdroite.setMaximumSize(new Dimension(300,200));
	    panelbasdroite.setSize(new Dimension(300,200));
            panelbasdroite.setBackground(Color.white);
            
	    panelbasmiddlehaut = new JPanel();
	    panelbasmiddlehaut.setLayout(new BoxLayout(panelbasmiddlehaut,BoxLayout.X_AXIS));
            panelbasmiddlehaut.setBackground(Color.white);
            
	    panelbasmiddlebas = new JPanel();
	    panelbasmiddlebas.setLayout(new BoxLayout(panelbasmiddlebas,BoxLayout.X_AXIS));
            panelbasmiddlebas.setBackground(Color.white);
	 }
      
	 public void createcomponent()
	 {
                labelcarte = new JLabel("Historique");
                labelcarte.setFont(new Font("italique",Font.BOLD,20));
                labelcarte.setForeground(Color.black);
                labelcarte.setBackground(Color.white);
	  }
         
	  public void addcomponent()
          {   
                paneltop.add(Box.createHorizontalStrut(20));
                paneltop.add(labelcarte);
	   }
          
           public void createlist()
           {
                     
                 for(int i=0;i<carteps.getDatelist().size();i++)
                 {
                         JPanel mainpanel = new JPanel();
                         JPanel panelhaut = new JPanel();
                         
                         panelhaut.setLayout(new BoxLayout(panelhaut,BoxLayout.X_AXIS));
                         panelhaut.setBackground(Color.white);
                         
                         mainpanel.setLayout(new BoxLayout(mainpanel,BoxLayout.Y_AXIS));
                         mainpanel.setMaximumSize(new Dimension(700,300));
                         mainpanel.setSize(new Dimension(700,300));
                         mainpanel.setBackground(Color.white);
                         
                         JLabel labeltitre = new JLabel(carteps.getDescription().get(i).toString());
                         JLabel labeldate = new JLabel(carteps.getDatelist().get(i).toString());

                         panelhaut.add(labeltitre);
                         panelhaut.add(Box.createHorizontalStrut(20));
                         panelhaut.add(labeldate);
                         panelhaut.add(Box.createHorizontalStrut(20));

                         mainpanel.add(panelhaut);
      
                         listpanel.add(mainpanel);
                }

                for(int i=0;i<listpanel.size();i++)
                {
                    panelmiddle.add(listpanel.get(i));
                    panelmiddle.setBackground(Color.white);
                    //panelmiddle.setFont(new Font("italique",Font.BOLD,15));
                }
         }
}